package com.rabbbit.demo.dlx;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Profile(value = "dlx")
@Configuration
public class RabbitMQConfig {

    @Bean
    public Queue queue(){
        Queue queue = new Queue("queue");
        queue.addArgument("x-message-ttl",5000);
        queue.addArgument("x-dead-letter-exchange", "dlx.direct.exchange");
        queue.addArgument("x-dead-letter-routing-key","dlx.queue");
        return queue;
    }

    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("direct.exchange");
    }

    @Bean
    public Binding binding(){
        return BindingBuilder.bind(queue()).to(directExchange()).withQueueName();
    }
}
